/*0GI1xcoeligdpMeXoHBphuyTSZBlvykvblI1N28fhKG0cr4a2Jgf3gTWLqXtf9o4*/
import { ajax, base, toast, cardCache } from 'nc-lightapp-front';
import { tableId, dataSource, formId } from '../constants';
import { innerButton } from '../../../../public/components/pubUtils/buttonName.js';
import { copyInner, resetBodyPk, clearTopInfos, calculateHeadMoney, deleteInner, pasteInner } from '../../../../public/components/pubUtils/billPubUtil.js';
import { cardBodyControl } from '../../../../public/components/pubUtils/buttonvisible.js';
import { modifyChecknoItemtype } from '../../../../public/components/pubUtils/specialFieldAfterEvent.js';
let { getDefData, setDefData } = cardCache;
export default function (that, props, key, text, record, index) {

    switch (key) {
        // 表格操修改
        case innerButton.open_browse:
            props.cardTable.toggleRowView(tableId, record);
            break;
        case innerButton.Close_browse:
            props.cardTable.toggleRowView(tableId, record);
            break;
        case innerButton.open_edit:
            let ishideAdd = false
            let cardData = that.props.createMasterChildData(that.getPagecode(), that.formId, that.tableId);
            if(cardData && cardData.body && cardData.body[that.tableId] && cardData.body[that.tableId].rows){
                let bodyrows= cardData.body[that.tableId].rows;
                for(let i=0;i<bodyrows.length;i++){
                    let top_billid = bodyrows[i].values.top_billid.value
                    let top_itemid = bodyrows[i].values.top_itemid.value
                    if( top_billid || top_itemid ){
                        ishideAdd = true
                        break
                    }
                }
            }
            that.setState({hideAdd: ishideAdd})
            //动态修改票据号字段类型
            modifyChecknoItemtype(props, that.tableId, record.values.pk_org_v.value, record.values.checktype.value)
            props.cardTable.openModel(tableId, 'edit', record, index);
            break;
        case innerButton.Copy_inner:
            copyInner(record, dataSource,that);
            that.setState({
                buttonfalg: false
            }, () => {
                cardBodyControl(props, that.state.buttonfalg);
            })
            break;
        case innerButton.Insert_inner:
            let data = props.createMasterChildData(that.getPagecode(), formId, tableId);
            //清空cardData的表体
            data.body[tableId].rows = [];
            ajax({
                url: '/nccloud/arap/gatheringbill/addline.do',
                data: data,
                success: (res) => {
                    if (res.data && res.data.body) {
                        props.cardTable.addRow(tableId, index, res.data.body[tableId].rows[0].values);
                    } else {
                        props.cardTable.addRow(tableId);
                    }
                }
            });
            break;
        case innerButton.Delete_inner:
            deleteInner(that, props, tableId, index);
            //删行之后控制肩部按钮
            that.onSelected();
            break;
        case innerButton.Paste_inner:
            pasteInner(that, props, dataSource, tableId, index)
            break;
        default:
            break;
    }
};

/*0GI1xcoeligdpMeXoHBphuyTSZBlvykvblI1N28fhKG0cr4a2Jgf3gTWLqXtf9o4*/